'use strict';

const Controller = require('egg').Controller;

class booksController extends Controller {
  //获取所有书籍
  async getAllbooks() {
    let r = await this.ctx.service.booksService.selectAllBooks();
    this.ctx.response.body = r;
  }
  //分页查询书籍
  async getBooksCutPage() {
    let { nowPage, maxResult } = this.ctx.request.query;
    nowPage = parseInt(nowPage);
    maxResult = parseInt(maxResult);
    let r = await this.ctx.service.booksService.selectBooksCutPage(nowPage, maxResult);
    this.ctx.response.body = r;
  }
  //添加书籍
  async addBooks() {
    const { ctx } = this;
    let booksinfo = ctx.request.body;
    let res = await ctx.service.booksService.insertBooks(booksinfo);
    ctx.body = res;
    // console.log("2222",booksinfo);
	}

   //查询书籍
   async searchBooks() {
    const { ctx } = this;
    let searchinfo = ctx.request.query;
    // console.log("2222",searchinfo);
    let res = await ctx.service.booksService.searchBookss(searchinfo);
    ctx.body = res;
	}

  //修改书籍
   async editBooks() {
    const { ctx } = this;
    let {editbooksinfo,id}= ctx.request.body;
    // console.log("2222",editbooksinfo,id);
    let res = await ctx.service.booksService.editBooks(editbooksinfo,id);
    ctx.body = res;
	}

  //删除书籍
  async removeBooks() {
    const { ctx } = this;
    let deleteid= ctx.request.query;
    // console.log("2222",deleteid);
    let res = await ctx.service.booksService.removeBooks(deleteid);
    ctx.body = res;
	}
}

module.exports = booksController;